package com.wn.servlet;

import com.wn.bean.Student;
import com.wn.mapper.StuMapper;
import com.wn.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author yellow Docter
 * @date 2022 -06-30
 * @desc
 */
@WebServlet("/queryStus")
public class QueryStusServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    //处理请求
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // 01 拿到数据

        //02 查询数据库
        SqlSession sqlSession = MyBatisUtils.getSqlSession();

        StuMapper mapper = sqlSession.getMapper(StuMapper.class);
        List<Student> stus = mapper.findStus();

        // 转发操作发送到页面
        request.setAttribute("stus",stus);
        request.getRequestDispatcher("/stus.jsp").forward(request,response);

    }
}
